﻿using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace TestConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //var config = new ManualConfig()
            //    .WithOptions(ConfigOptions.DisableOptimizationsValidator)
            //    .AddValidator(JitOptimizationsValidator.DontFailOnError)
            //    .AddLogger(ConsoleLogger.Default)
            //    .AddColumnProvider(DefaultColumnProviders.Instance);

            //var boKar = BenchmarkRunner.Run<Foo>(config);


            //TestVolatile testVolatile = new TestVolatile();
            //testVolatile.Start1();


            //TestClassCtor test = new TestClassCtor();


            //TestMath testMath = new TestMath();
            //testMath.Test();


            //TestTcpClient.Test();

            //TestTask.Test();


            //TestIOCPApi.Test();


            //TestThreadPool.Test();


            HashSet<string> hset = new HashSet<string>();


            TestReverse.Test();

            Console.ReadLine();




            var b = new BaseB() { Name = "张三", NickName = "小张" };
            Console.WriteLine(b.HitTest<IBase>("张三")?.Name ?? "false");
            Console.WriteLine(b.HitTest<IBase>("小张")?.Name ?? "false");
        }
    }



    public interface IBase
    {
        string Name { get; }

        T? HitTest<T>(string name) where T : IBase;
    }

    public class BaseA : IBase
    {
        public string Name { get; set; }

        public virtual T? HitTest<T>(string name) where T : IBase
        {
            return this.Name == name ? (T)(IBase)this : default(T);
        }
    }

    public class BaseB : BaseA
    {
        public string NickName { get; set; }


        public override T? HitTest<T>(string name) where T : default
        {
            T? existing = base.HitTest<T>(name);
            if (existing != null)
            {
                return existing;
            }

            return this.NickName == name ? (T)(IBase)this : default(T);
        }

        //public override IBase? HitTest<IBase>(string name)
        //{
        //    T? existing = base.HitTest<IBase>(name);
        //    if (existing != null)
        //    {
        //        return existing;
        //    }

        //    return this.NickName == name ? this : null;
        //}
    }
}